#!/bin/bash
if [ $# != 1 ] ; then
 echo -e "\033[31m USAGE: phytium_env.sh OHOS_PATH_ROOT  \033[0m"
 echo -e "\033[31m example: ./phytium_env.sh /home/phytium/OpenHarmony  \033[0m"
 exit 1;
fi

OHOS_PATH=$1
if [ ! -d $OHOS_PATH ];then
    echo -e "\033[31mMake sure  the OHOS_PATH_root exist! \033[0m"
    exit 1;
fi

echo -e "\033[32mTHE OHOS_PATH_ROOT $OHOS_PATH \033[0m"
echo -e "\033[32m #### sync phytium env start！ #### \033[0m"

CURRENTPWD=$(pwd)


#sync device_soc_phytium
echo -e "\033[32m #### sync device_soc_phytium  #### \033[0m" 
mkdir -p $OHOS_PATH/device/soc/phytium/ 
cp device_soc_phytium/* $OHOS_PATH/device/soc/phytium  -R
echo -e "\033[32m #### sync device_soc_phytium end  #### \033[0m" 


#sync device_board_phytium
echo -e "\033[32m #### sync device_board_phytium  #### \033[0m"
mkdir -p $OHOS_PATH/device/board/phytium
cp device_board_phytium/*  $OHOS_PATH/device/board/phytium/ -R
echo -e "\033[32m #### sync device_board_phytium end  #### \033[0m"

#sync vendor_phytium
echo -e "\033[32m #### sync vendor_phytium  #### \033[0m"
mkdir -p $OHOS_PATH/vendor/phytium
cp vendor_phytium/*  $OHOS_PATH/vendor/phytium/ -R
echo -e "\033[32m #### sync vendor_phytium end  #### \033[0m"


#sync kenel
echo -e "\033[32m #### sync kernel  #### \033[0m"
cp device_board_phytium/e2000/kernel_source/e2000_patch  $OHOS_PATH/kernel/linux/patches/linux-5.10 -R 
cp device_board_phytium/e2000/kernel_source/e2000_standard_defconfig $OHOS_PATH/kernel/linux/config/linux-5.10/arch/arm64/configs
echo -e "\033[32m #### sync kernel end  #### \033[0m"





echo -e "\033[32m #### apply patch  ####\n \033[0m"
echo -e "\033[32m #### applay 0001_drivers_peripheral.patch  #### \033[0m"
cp device_board_phytium/e2000/patch/0001_drivers_peripheral.patch $OHOS_PATH/drivers/peripheral
cd $OHOS_PATH/drivers/peripheral
git apply 0001_drivers_peripheral.patch  
rm $OHOS_PATH/drivers/peripheral/0001_drivers_peripheral.patch
cd $CURRENTPWD
echo -e "\033[32m #### applay 0001_foundation_arkui_ace_engine.patch  #### \033[0m"
cp   device_board_phytium/e2000/patch/0001_foundation_arkui_ace_engine.patch  $OHOS_PATH/foundation/arkui/ace_engine
cd   $OHOS_PATH/foundation/arkui/ace_engine
git apply 0001_foundation_arkui_ace_engine.patch
rm $OHOS_PATH/foundation/arkui/ace_engine/0001_foundation_arkui_ace_engine.patch
cd $CURRENTPWD
echo -e "\033[32m #### applay 0001_foundation_graphic_graphic_2d.patch  #### \033[0m"
cp device_board_phytium/e2000/patch/0001_foundation_graphic_graphic_2d.patch  $OHOS_PATH/foundation/graphic/graphic_2d
cd  $OHOS_PATH/foundation/graphic/graphic_2d
git apply 0001_foundation_graphic_graphic_2d.patch
rm $OHOS_PATH/foundation/graphic/graphic_2d/0001_foundation_graphic_graphic_2d.patch

cd $CURRENTPWD
echo -e "\033[32m #### applay 0005_third_party_gstreamer_gstplugins_base.patch  #### \033[0m"
cp device_board_phytium/e2000/patch/0005_third_party_gstreamer_gstplugins_base.patch  $OHOS_PATH/third_party/gstreamer
cd  $OHOS_PATH/third_party/gstreamer
git apply 0005_third_party_gstreamer_gstplugins_base.patch
rm $OHOS_PATH/third_party/gstreamer/0005_third_party_gstreamer_gstplugins_base.patch

cd $CURRENTPWD
#echo -e "\033[32m #### applay 0006_foundation_multimedia_player_framework.patch  #### \033[0m"
#cp device_board_phytium/e2000/patch/0006_foundation_multimedia_player_framework.patch  $OHOS_PATH/foundation/multimedia/player_framework
#cd  $OHOS_PATH/foundation/multimedia/player_framework
#git apply 0006_foundation_multimedia_player_framework.patch
#rm $OHOS_PATH/foundation/multimedia/player_framework/0006_foundation_multimedia_player_framework.patch
#cd $CURRENTPWD

cd $CURRENTPWD
echo -e "\033[32m #### applay 0007_drivers_peripheral_camera_camera_hal.patch  #### \033[0m"
cp device_board_phytium/e2000/patch/0007_drivers_peripheral_camera_camera_hal.patch  $OHOS_PATH/drivers/peripheral/camera
cd  $OHOS_PATH/drivers/peripheral/camera
git apply 0007_drivers_peripheral_camera_camera_hal.patch
rm $OHOS_PATH/drivers/peripheral/camera/0007_drivers_peripheral_camera_camera_hal.patch
cd $CURRENTPWD


 echo -e "\033[32m #### applay patch end ####\n \033[0m"


echo -e "\033[32m #### sync phytium end！ #### \033[0m"
